<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="农忙互助订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="agriculturOrderCode">
              <a-input v-model="model.agriculturOrderCode" placeholder="请输入农忙互助订单编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workload">
              <a-input v-model="model.workload" placeholder="请输入工作量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="所需人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="needPeople">
              <a-input v-model="model.needPeople" placeholder="请输入所需人数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobProfile">
              <a-textarea v-model="model.jobProfile" rows="4" placeholder="请输入工作简介" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobAddress">
              <a-input v-model="model.jobAddress" placeholder="请输入工作地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工钱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hire">
              <a-input v-model="model.hire" placeholder="请输入工钱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="username">
              <a-input v-model="model.username" placeholder="请输入用户姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jobType">
              <a-input v-model="model.jobType" placeholder="请输入工种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否需接送（0接、1不接）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPickup">
              <a-input-number v-model="model.isPickup" placeholder="请输入是否需接送（0接、1不接）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作距离" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workDistance">
              <a-input v-model="model.workDistance" placeholder="请输入工作距离"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自备工具" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="selfTools">
              <a-input v-model="model.selfTools" placeholder="请输入自备工具"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户所在位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workLocation">
              <a-input v-model="model.workLocation" placeholder="请输入用户所在位置"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邀请状态(0已邀请、1未邀请)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invitationStatus">
              <a-input-number v-model="model.invitationStatus" placeholder="请输入邀请状态(0已邀请、1未邀请)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userid">
              <a-input v-model="model.userid" placeholder="请输入用户id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单状态（0已完成、1未完成）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderStatus">
              <a-input v-model="model.orderStatus" placeholder="请输入订单状态（0已完成、1未完成）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="个人简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="personalProfile">
              <a-input v-model="model.personalProfile" placeholder="请输入个人简介"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'AgriculturAlassistancePersonForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           agriculturOrderCode: [
              { required: true, message: '请输入农忙互助订单编号!'},
           ],
           needPeople: [
              { required: true, message: '请输入所需人数!'},
           ],
        },
        url: {
          add: "/agricultural/assistancePerson/add",
          edit: "/agricultural/assistancePerson/edit",
          queryById: "/agricultural/assistancePerson/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>